home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / internet / faq / englisch / comp.lang.tcl < prev    next >
Encoding:
Text File  |  1995-04-11  |  49.2 KB  |  1,452 lines

  1. Posted-By: auto-faq 3.1.1.2
  2. Archive-name: tcl-faq/usage
  3. Posting-Frequency: monthly
  4.  
  5.  
  6.                    TCL LANGUAGE USAGE QUESTIONS AND ANSWERS
  7.  
  8. INTRODUCTION
  9.  
  10.    This FAQ file is intended to address some of the most commonly asked
  11.    questions regarding the Tcl programming language. It is hoped that by
  12.    addressing these here in this document, that the postings to
  13.    comp.lang.tcl will be of a less repetitive and more informative
  14.    nature. It is also hoped that via this and other available resources,
  15.    more and more people will be able to utilize Tcl and Tcl based
  16.    applications.
  17.  
  18.    This FAQ is maintained by Joe Moss (joe@morton.rain.com) and is posted
  19.    monthly to comp.lang.tcl and news.answers and can also be obtained
  20.    from the Tcl archive at ftp.aud.alcatel.com (198.64.191.10) in the
  21.    /tcl/docs directory or via the World Wide Web as
  22.    http://route.psg.com/tcl.html.
  23.  
  24.    Note that this FAQ deals with Tcl, not with Tk. For Tk Toolkit Q&As
  25.    see the FAQ posting by Thomas J. Accardo (tja@cpu.com) (see the
  26.    question below, entitled "Where can I get further info about Tcl" for
  27.    pointers to other Tcl FAQs). However, there is some inevitable
  28.    overlap. Some of the most commonly asked questions about usage of the
  29.    Tk widgets are due to mis-understandings of how the Tcl interpreter
  30.    works. These issues may still be addressed here. Also, some examples
  31.    of Tcl usage may involve the use of the Tk widgets.
  32.  
  33.    Questions and Answers about the use of non-Tk related extensions (such
  34.    as Extended Tcl and Expect, but not TkX, expectk, BLT, etc.) are also
  35.    appropriate here.
  36.  
  37.    The source of this document is now maintained in HTML. It is then run
  38.    through a couple of scripts (written in Tcl, of course) to
  39.    automagically add question numbers, generate the Index of Questions,
  40.    and add the From and Subject lines to the text version. The version
  41.    available via the WWW will be updated whenever there are changes,
  42.    while the ASCII text version will be generated and posted only once a
  43.    month.
  44.  
  45.    Last modified: Wed Mar 01 00:53:48 PST 1995
  46.      _________________________________________________________________
  47.  
  48. Index of Questions:
  49.  
  50.   GENERAL INFORMATION:
  51.      * Q1- Where can I get further info about Tcl?
  52.      * Q2- Where can I find help getting Tcl to work on my machine?
  53.      * Q3- How can I combine Tcl and C?
  54.      * Q4- How do I combine several extensions to provide all the
  55.        features I want?
  56.      * Q5- What about dynamic loading?
  57.      * Q6- How do I create a stand alone program in case Tcl isn't
  58.        installed?
  59.      * Q7- How do I make my script executable regardless of the location
  60.        of tclsh?
  61.      * Q8- Why isn't <some extension> part of the standard distribution?
  62.  
  63.   PROGRAMMING RELATED QUESTIONS AND ANSWERS:
  64.      * Q9- How can I create/use association lists or property lists?
  65.      * Q10- How can I generate a random number in Tcl?
  66.      * Q11- How can I call one proc with the multi parameter value
  67.        returned by another proc?
  68.      * Q12- How can I pass an array into a proc?
  69.      * Q13- How can I run an external command and read its output via a
  70.        pipe?
  71.      * Q14- How can I delete a procedure from within a script?
  72.      * Q15- How can I get more than 7 digits of double precision?
  73.      * Q16- How can I grab the command line when a non-built-in call is
  74.        made?
  75.      * Q17- How can I get or set an environment variable?
  76.      * Q18- How can I use numbers with leading zeroes?
  77.      * Q19- How can I find the command line arguments to my application?
  78.      * Q20- How can I put comments in my script, e.g. in a case
  79.        statement?
  80.      * Q21- How can I input and output binary data?
  81.      * Q22- How can I trap signals, and perform other more Unix specific
  82.        functions?
  83.      * Q23- How can I do a double indirect? - Why doesn't $$var work?
  84.      * Q24- How can I get quoted strings to work the way I want?
  85.      * Q25- How can I share procedures between multiple tcl applications?
  86.      * Q26- How can I get items inserted into a list?
  87.      * Q27- How can I perform a non-blocking read on a file identifier?
  88.      * Q28- How can I read and write from a pipe without locking up?
  89.      * Q29- How can I find what version I am running?
  90.      * Q30- How can I use variables to hold array names?
  91.  
  92.   PLATFORM SPECIFIC AND PORTABILITY RELATED QUESTIONS:
  93.      * Q31- How can I create shared Tcl/Tk libraries on AIX
  94.      * Q32- Has anyone gotten Tcl to compile under HP-UX?
  95.      * Q33- Has anyone gotten Tcl to compile under VMS?
  96.      * Q34- What does it take to get Tcl to compile under SCO Unix?
  97.      * Q35- Why do I get format and scan errors when I run tclTest?
  98.      * Q36- Why do I get lots of errors under Irix 4.0.1 when I run
  99.        tclTest?
  100.      * Q37- Does anyone else have problems with Tcl on a Cray?
  101.      * Q38- How do I install Tcl 7.1/Tk 3.4 on NeXTSTEP 3.1?
  102.      * Q39- Installing TCL7.1 on NeXT
  103.      * Q40- Installing TK3.4 on NEXTSTEP 3.1
  104.      * Q41- Why can't I print the draft of the Tcl/Tk book?
  105.      * Q42- Why am I getting errors on my SGI Indigo workstation?
  106.      * Q43- How do I build expect on Solaris 2.3?
  107.      * Q44- How do I port Tcl and Tk to a Sequent?
  108.      * Q45- How do I get around the symbol table full msg in AU/X 3.0?
  109.      * Q46- How do I compile Tcl on MS-DOS, MacOS, or other non-UNIX
  110.        system?
  111.      * Q47- How do I get Tcl to compile on my QNX system?
  112.      * Q48- Why do I get the error message "Command not found" when I try
  113.        to run a Tcl script?
  114.  
  115.      _________________________________________________________________
  116.  
  117.   GENERAL INFORMATION:
  118.  
  119. ------------------
  120.  
  121. From: Tcl Q&A
  122. Subject: Q1- Where can I get further info about Tcl?
  123.  
  124.    The newsgroup comp.lang.tcl is for discussion of the Tcl language and
  125.    packages based on it. There are several FAQ documents related to Tcl
  126.    available from ftp.aud.alcatel.com in the /tcl/docs directory that
  127.    provide further information and pointers to yet more reading material,
  128.    both on-line and in print. They can also be accessed via the World
  129.    Wide Web:
  130.    http://www.cis.ohio-state.edu/hypertext/faq/usenet/tcl-faq/top.html
  131.  
  132.    Two other good starting points, if you are surfing the Web for
  133.    information, are: http://www.sco.com/IXI/of_interest/tcl/Tcl.html and
  134.    http://web.cs.ualberta.ca/%7Ewade/HyperTcl/.
  135.  
  136.    Of course, the source distribution itself includes a great deal of
  137.    documentation. The latest version is 7.3, with the 7.4b2 beta release
  138.    also available. Both can be obtained from:
  139.    ftp://ftp.cs.berkeley.edu/ucb/tcl/. 
  140.  
  141. ------------------
  142.  
  143. From: Tcl Q&A
  144. Subject: Q2- Where can I find help getting Tcl to work on my machine?
  145.  
  146.    Look in the Tcl distribution for the file called porting.notes. This
  147.    will contain a collection of notes that various people have provided
  148.    about porting Tcl to various machines and operating systems. There is
  149.    also a file called README which should be read FIRST - before doing
  150.    anything else with the code (this should always be one's first step
  151.    with any package).
  152.  
  153.    There are also several questions and answers related to building the
  154.    interpreter on various platforms at the end of this document. 
  155.  
  156. ------------------
  157.  
  158. From: Tcl Q&A
  159. Subject: Q3- How can I combine Tcl and C?
  160.  
  161.    Tcl was intended to be used along with C code. Because of this, there
  162.    are several ways to combine the two. Here is a list of some of them
  163.    (with man page references for further info):
  164.      * Adding Commands to Tcl (Tcl_CreateCommand)
  165.      * Command Traces (Tcl_CreateTrace)
  166.      * Variable Traces (Tcl_TraceVar)
  167.      * Getting/Setting Variables (Tcl_GetVar/Tcl_SetVar)
  168.      * Linking Variables (Tcl_LinkVar)
  169.      * Asynchronous Event Handlers (Tcl_AsyncCreate)
  170.      * Adding Functions to expr Command (Tcl_CreateMathFunc)
  171.      * Custom tclAppInit Routine (Tcl_AppInit)
  172.      * Custom main Routine (Tcl_Main)
  173.      * Via Pipes (open)
  174.      * exec Command (exec)
  175.  
  176.    The last two do not provide nearly the same level of integration as
  177.    those near the top of the list, but they are necessary if you do not
  178.    have access to the source code.
  179.  
  180.    There is plenty of documentation available that explains this in
  181.    further detail. See the TclCommandWriting man page, included with
  182.    Extended Tcl or available via the WWW at
  183.    http://psg.com/~joem/CmdWrite.html
  184.  
  185.    See also part two of Larry's Tcl FAQ and the Tcl Bibliography for
  186.    other references.
  187.  
  188.    In addition to all the ways possible with standard Tcl, several
  189.    extensions add others, notably via pseudo-ttys with expect, and via X
  190.    event, file event, timer, and idle callback handlers with Tk. Also
  191.    check out Embedded Tk, available from
  192.    ftp://ftp.std.com/pub/drh/et1_0.tar.gz 
  193.  
  194. ------------------
  195.  
  196. From: Tcl Q&A
  197. Subject: Q4- How do I combine several extensions to provide all the
  198.     features I want?
  199.  
  200.    The simple answer is to create a custom Tcl_AppInit function to call
  201.    the Init procedures for each of the desired extensions. This can be
  202.    done by copying the tclAppInit.c (tkAppInit.c for Tk apps) file from
  203.    Tcl source distribution, modifying it, and then linking your
  204.    Tcl_AppInit function with the Tcl library. For example, the standard
  205.    Tcl_AppInit looks like this:
  206.  
  207.     int
  208.     Tcl_AppInit(interp)
  209.         Tcl_Interp *interp; /* Interpreter for application. */
  210.     {
  211.         /* ... */
  212.  
  213.         if (Tcl_Init(interp) == TCL_ERROR) {
  214.             return TCL_ERROR;
  215.         }
  216.  
  217.         /* ... */
  218.     }
  219.  
  220.    In order to add the foo extension, you would add a call to the foo
  221.    init function, like this:
  222.  
  223.     int
  224.     Tcl_AppInit(interp)
  225.         Tcl_Interp *interp; /* Interpreter for application. */
  226.     {
  227.         /* ... */
  228.  
  229.         if (Tcl_Init(interp) == TCL_ERROR) {
  230.             return TCL_ERROR;
  231.         }
  232.  
  233.         if (Foo_Init(interp) == TCL_ERROR) {
  234.             return TCL_ERROR;
  235.         }
  236.  
  237.         /* ... */
  238.     }
  239.  
  240.    For more information, see the Tcl_AppInit man page and the
  241.    tclAppInit.c file.
  242.  
  243.    The more complete answer is that the simple answer doesn't always
  244.    work. Many extensions require more extensive modifications and the way
  245.    to combine them depends on the specific extensions involved.
  246.  
  247.    If you wish to include Extended Tcl, you should start with the
  248.    Tcl_AppInit function that comes with it. Also make sure when you link
  249.    the program that you include the Extended Tcl library before the
  250.    standard Tcl library, for example:
  251.  
  252.     cc -o mytclsh mytclXAppInit.c -ltclx -ltcl ...
  253.  
  254.    or for an interpreter including the Tk extensions:
  255.  
  256.     cc -o mywish mytkXAppInit.c -ltkx -ltk -ltclx -ltcl ...
  257.  
  258.    On the positive side, there are also several packages available that
  259.    can aid in combining extensions, such as Make-A-Wish, or extensions
  260.    that include configuration files for combining them with other popular
  261.    extensions. For example, several extensions written by Sven Delmas
  262.    allow you to specify options to configure to generate a Makefile that
  263.    will build an interpreter containing the specified extensions. See
  264.    part four of Larry Virden's FAQ for the location of these and other
  265.    packages. 
  266.  
  267. ------------------
  268.  
  269. From: Tcl Q&A
  270. Subject: Q5- What about dynamic loading?
  271.  
  272.    The issue of dynamic loading appears fairly often in comp.lang.tcl and
  273.    yes, the ideal method of combining extensions would be to use dynamic
  274.    loading, but the standard Tcl distribution does not currently support
  275.    it.
  276.  
  277.    The syntax of the load command has pretty much already been worked
  278.    out. It is just a matter of implementing it on a large number of
  279.    platforms (this is something that is definately platform dependent).
  280.  
  281.    Here is an excerpt from a message, dated 14 Jul 1993, written by John
  282.    Ousterhout on the subject:
  283.  
  284.      At the [1993 Tcl] workshop we decided to standardize on a simple Tcl
  285.      command interface for dynamic loading. The command syntax will be as
  286.      follows:
  287.  
  288.         load <file>
  289.  
  290.      where <file> is the name of a dynamically-loadable object file such
  291.      as libtcl.so. The syntax of these names may vary from system to
  292.      system according to local custom, but part of the name should be the
  293.      package prefix for the package, such as tcl in the above example.
  294.  
  295.      The load command must load the given object file, pick the package
  296.      prefix out of the file name, then invoke the procedure
  297.      <prefix>_Init, where <prefix> is the package prefix with the first
  298.      letter capitalized, e.g. Tcl_Init or Dp_Init or Tclx_Init. Each
  299.      loadable package must contain an initialization procedure that takes
  300.      a single argument that is a (Tcl_Interp *):
  301.  
  302.         int Dp_Init(Tcl_Interp *interp);
  303.  
  304.      The init procedure adds all of that package's Tcl commands into the
  305.      interpreter, plus performs any other package-specific
  306.      initialization. It returns a standard Tcl completion code and leaves
  307.      an error message or result value in the interpreter, which is
  308.      returned as the result of the load command.
  309.  
  310.    Implementations for certain platforms are already available, check the
  311.    software catalog (parts four and five of Larry Virden's FAQ) for
  312.    details (e.g. the Shells package) and also see the paper by Kevin
  313.    Kenny from the 1994 Tcl workshop proceedings available from
  314.    http://crdis1.ge.com/papers/gecrd/mtl/mdip/tcl94/00header.html.
  315.    Hopefully soon this will become part of the standard distribution. 
  316.  
  317. ------------------
  318.  
  319. From: Tcl Q&A
  320. Subject: Q6- How do I create a stand alone program in case Tcl isn't
  321.     installed?
  322.  
  323.    Earle Lowe (lowee@cpsc.ucalgary.ca) has replied that:
  324.  
  325.      If you want to create a stand-alone program that will run anywhere
  326.      regardless of the presence/absence of TCL/Tk, than you need to go
  327.      through some more work.
  328.  
  329.      Basically, this involves converting the TCL init files to C strings,
  330.      and then rather than calling Tcl_Init() and Tk_Init(), you call
  331.      Tcl_Eval() with the converted C strings as arguments.
  332.  
  333.      I suggest getting the wish_compiler package by Alexei Rodriguez
  334.      (alexei@cis.ufl.edu) from
  335.      ftp://ftp.aud.alcatel.com/tcl/code/wish_compiler.shar.gz 
  336.  
  337.      This package contains a tcl2c converter, and instructions as to its
  338.      use.
  339.  
  340.      With some Makefile magic, you can use using TCL/Tk as intended (as
  341.      an interpreted language using some version of wish) and when the
  342.      code works, you can create a stand-alone compiled program.
  343.  
  344.    Another option that is now available is "Embedded Tk". You can get it
  345.    from ftp://ftp.std.com/pub/drh/et1_0.tar.gz 
  346.  
  347. ------------------
  348.  
  349. From: Tcl Q&A
  350. Subject: Q7- How do I make my script executable regardless of the location
  351.     of tclsh?
  352.  
  353.       Or how can I automatically pass my script through tclsh without
  354.       specifying a fixed path?
  355.  
  356.    There are several tricks you can use, but the most common is to make
  357.    use of the fact that, in Tcl, the backslash character works as a line
  358.    continuation indicator, even within comments. So instead of:
  359.  
  360.         #! /usr/local/bin/tclsh
  361.  
  362.         puts "Hello World"
  363.  
  364.    You could use:
  365.  
  366.         #! /bin/sh
  367.         # The next line is executed by /bin/sh, but not Tcl \
  368.           exec tclsh $0 ${1+"$@"}
  369.  
  370.         puts "Hello World"
  371.  
  372.    and the script will run regardless of where tclsh is located (as long
  373.    as it is in one of the directories in the user's PATH). 
  374.  
  375. ------------------
  376.  
  377. From: Tcl Q&A
  378. Subject: Q8- Why isn't <some extension> part of the standard distribution?
  379.  
  380.    Often people ask why some language extension that they use often (in
  381.    fact, they may find it indispensible) isn't merged into the core
  382.    language.
  383.  
  384.    It must be remembered that a lot of people use Tcl on widely differing
  385.    systems and in vastly different ways. Also, Tcl was originally
  386.    intended as an embedded language that would provide the minimal
  387.    programming constructs and framework upon which a programmer could
  388.    base the scripting language for their application.
  389.  
  390.    Having said that, the core Tcl language has grown over the years. Some
  391.    of the added features have come from extensions written by others.
  392.    When the capabilities provided by extensions are deemed to be of
  393.    sufficient value to all users of Tcl, John has added them to the base
  394.    language. Some examples are associative arrays, the file I/O commands
  395.    (and file handles), and the unknown procedure, all of which appeared
  396.    in Extended Tcl before becoming part of standard Tcl. Tk 4.0 will
  397.    contain (and Tk4.0b2 does now contain) the equivalent functionality of
  398.    the addinput and photo widget extensions that were written by others
  399.    for Tcl 7.x/Tk 3.x.
  400.      _________________________________________________________________
  401.  
  402.   PROGRAMMING RELATED QUESTIONS AND ANSWERS:
  403.  
  404. ------------------
  405.  
  406. From: Tcl Q&A
  407. Subject: Q9- How can I create/use association lists or property lists?
  408.  
  409.    Use arrays or Extended Tcl keyed lists.
  410.  
  411.    For example, if you did a:
  412.  
  413.     keylset ttyFields ttyName tty1a
  414.     keylset ttyFields baudRate 57600
  415.     keylset ttyFields parity strip
  416.  
  417.    And then an echo $ttyFields, you'd get:
  418.  
  419.     {ttyName tty1a} {baudRate 57600} {parity strip}
  420.  
  421.    Or using arrays:
  422.  
  423.     set ttyFields(ttyName)  tty1a
  424.     set ttyFields(baudRate) 57600
  425.     set ttyFields(parity)   strip
  426.  
  427. ------------------
  428.  
  429. From: Tcl Q&A
  430. Subject: Q10- How can I generate a random number in Tcl?
  431.  
  432.    Extended Tcl includes a command named random to do this. For example,
  433.    to generate a random number between 0 and 9 inclusive:
  434.  
  435.     set random_number [random 10]
  436.  
  437.    It also has a srandom command to seed the random number generator.
  438.  
  439.    Several pseudo-random number generator functions, written in straight
  440.    Tcl, have been posted to comp.lang.tcl, see Larry's tcl-faq/part4 for
  441.    a list.
  442.  
  443.    To get a value you can use as a seed, you might try one (or a
  444.    combination) of these:
  445.  
  446.     [pid]
  447.     [file atime /dev/kmem]
  448.     [getclock]        (Extended Tcl only)
  449.  
  450. ------------------
  451.  
  452. From: Tcl Q&A
  453. Subject: Q11- How can I call one proc with the multi parameter value
  454.     returned by another proc?
  455.  
  456.    Assuming y requires multiple args and x returns multiple words, use
  457.    Tcl's eval command:
  458.  
  459.     eval y [x]
  460.  
  461. ------------------
  462.  
  463. From: Tcl Q&A
  464. Subject: Q12- How can I pass an array into a proc?
  465.  
  466.    Use upvar rather than try to use global variables when possible. If
  467.    the function is event driven, you are forced to use global variables.
  468.  
  469.     # print elements of an array
  470.     proc show_array arrayName {
  471.         upvar $arrayName myArray
  472.  
  473.         foreach element [array names myArray] {
  474.            puts stdout "${arrayName}($element) =  $myArray($element)"
  475.         }
  476.     }
  477.  
  478.     set arval(0) zero
  479.     set arval(1) one
  480.     show_array arval
  481.  
  482.    To return an array from a procedures, just take the array name in as
  483.    an argument, as above. Any changes you make in the array will be made
  484.    in the parent's array as well.
  485.  
  486.    Extended Tcl introduces a concept called keyed lists which are arrays
  487.    made out of lists of key-value pairs and can be passed by value to
  488.    routines, over networks, etc. 
  489.  
  490. ------------------
  491.  
  492. From: Tcl Q&A
  493. Subject: Q13- How can I run an external command and read its output via a
  494.     pipe?
  495.  
  496.    For example, to grep a pattern out of a range of files, one might do:
  497.  
  498.    Karl Lehenbauer (karl@NeoSoft.com) writes:
  499.  
  500.     set files [glob /home/cole/stats/*]
  501.  
  502.     proc parseInfo { site } {
  503.        global files
  504.  
  505.     #
  506.     # site is chosen from a listbox earlier
  507.     #
  508.        set in [open [concat "|/usr/bin/grep $site $files"] r]
  509.  
  510.        while {[gets $in line]>-1} {
  511.           puts stderr $line
  512.        }
  513.        catch {close $in}
  514.     }
  515.  
  516.    One thing: the matching strings are not returned in directory order.
  517.  
  518.    But what if I want to check the return code AND use the output of the
  519.    command? Kevin B. Kenny (kennykb@dssv01.crd.ge.com) writes:
  520.  
  521.     if [catch {exec ls} data] {
  522.         # The exec got an error, and $errorCode has its termination status
  523.     } else {
  524.         # The exec succeeded
  525.     }
  526.     # In any case, `data' contains all the output from the child process.
  527.  
  528.    Note that Karl Lehenbauer (karl@NeoSoft.com) adds that errorCode will
  529.    be a list containing three elements, the string "CHILDSTATUS", the
  530.    process ID of the child, and the exit status of the child. 
  531.  
  532. ------------------
  533.  
  534. From: Tcl Q&A
  535. Subject: Q14- How can I delete a procedure from within a script?
  536.  
  537.    Rename the procedure to have no name, for example:
  538.  
  539.     rename procedureName ""
  540.  
  541. ------------------
  542.  
  543. From: Tcl Q&A
  544. Subject: Q15- How can I get more than 7 digits of double precision?
  545.  
  546.    In Tcl 7.x, set the global variable tcl_precision to a value in the
  547.    range 1-17. For example:
  548.  
  549.     % expr 4*atan(1)
  550.     3.14159
  551.     % set tcl_precision 0
  552.     can't set "tcl_precision": improper value for precision
  553.     % set tcl_precision 3
  554.     3
  555.     % expr 4*atan(1)
  556.     3.14
  557.     % set tcl_precision 16
  558.     16
  559.     % expr 4*atan(1)
  560.     3.141592653589793
  561.     % set tcl_precision 18
  562.     can't set "tcl_precision": improper value for precision
  563.  
  564.    In Tcl 6.x, you must modify the tclExpr.c module to use %lf instead of
  565.    %g. 
  566.  
  567. ------------------
  568.  
  569. From: Tcl Q&A
  570. Subject: Q16- How can I grab the command line when a non-built-in call is
  571.     made?
  572.  
  573.    The procedure unknown is called automatically with arguments
  574.    containing the command and its arguments for any command that couldn't
  575.    be found. In fact, Tcl and Extended Tcl use this feature to provide
  576.    demand loaded commands, and even entire libraries. Also, when using
  577.    the "tclsh" or "tcl" shells interactively, the unknown procedure
  578.    enables the shell to run external programs (i.e. without typing "exec"
  579.    first).
  580.  
  581.    So by modifying the unknown procedure you can provide your own
  582.    extended functionality, or even remove the demand loading capability
  583.    if you so desire. 
  584.  
  585. ------------------
  586.  
  587. From: Tcl Q&A
  588. Subject: Q17- How can I get or set an environment variable?
  589.  
  590.    By using something like the following.
  591.  
  592.     set olddisplay $env(DISPLAY)
  593.     set env(DISPLAY) unix:0
  594.  
  595.    Thanks to Joel Fine (joel@cs.berkeley.edu) for the answer.
  596.  
  597.    You can also check if an environment variable exists, like this:
  598.  
  599.     if [info exists env(VARNAME)] {
  600.         # okay, it's there use it
  601.         set value $env(VARNAME)
  602.     } else {
  603.         # the environment var isn't set, use a default
  604.         set value "the default value"
  605.     }
  606.  
  607. ------------------
  608.  
  609. From: Tcl Q&A
  610. Subject: Q18- How can I use numbers with leading zeroes?
  611.  
  612.    Dave Morriss was having problems because he was trying to do something
  613.    like:
  614.  
  615.     set index [expr [exec date +%W]%[llength $pop_server_list]]
  616.  
  617.    but during the 8th and 9th week of the year, he got errors, since 08
  618.    and 09 are not valid octal numbers. Actually, Tcl first tries to
  619.    interpret numbers starting with a zero as an octal number, but if that
  620.    fails (i.e. because of invalid octal digits like 8 and 9), the value
  621.    is then interpreted as a floating point value; the % (modulo) function
  622.    only operates on integer values.
  623.  
  624.    Some of the solutions provided were:
  625.  
  626.    From George A. Howlett (george.howlett@att.com), we got:
  627.  
  628.     set wknum [format "%g" [exec date +%W]]
  629.     set index [expr [exec $wknum%[llength $pop_server_list]]
  630.  
  631.    From Fred Feirtag (feirtag@wave.nrl.navy.mil):
  632.  
  633.     set index [expr (1[exec date +%W]-100)%[llength $pop_server_list]]
  634.  
  635.    From Dan R. Schenck (schendr@Texaco.com):
  636.  
  637.     set index [expr [string trimleft [exec date +%W] 0]%[llength \
  638.              $pop_server_list]]
  639.  
  640.    Jay Goldberg (jayg@accessware.com) points out that while all of the
  641.    above work in this case (dealing with a date) they don't work in the
  642.    general case.
  643.  
  644.    Instead you can use the statement:
  645.  
  646.     regsub 0+(.+) orig_string \\1 new_string
  647.  
  648.    to strip off leading zeros. So, applying this to the example above:
  649.  
  650.     regsub 0+(.+) [exec date +%W] \\1 weeknum
  651.     set index [expr $weeknum%[llength $pop_server_list]]
  652.  
  653. ------------------
  654.  
  655. From: Tcl Q&A
  656. Subject: Q19- How can I find the command line arguments to my application?
  657.  
  658.    The program name is assigned to the global variable argv0 and any
  659.    arguments to it are placed in the global variable argv as a list. The
  660.    variable argc is set to the number of elements in the list argv. As an
  661.    example:
  662.  
  663.     #! /usr/local/bin/tclsh
  664.  
  665.     if { $argc != 2 } {
  666.         puts stderr "$argv0: Usage: $argv0 <infile> <outfile>"
  667.         exit 1
  668.     }
  669.  
  670.     set infile  [lindex $argv 0]
  671.     set outfile [lindex $argv 1]
  672.  
  673. ------------------
  674.  
  675. From: Tcl Q&A
  676. Subject: Q20- How can I put comments in my script, e.g. in a case
  677.     statement?
  678.  
  679.    You can't have comments where you have them. Move the comments inside
  680.    of the { for the case that you want. Your code should read:
  681.  
  682.     case 1 {
  683.       -1    {
  684.             #
  685.             # Cannot find information sought
  686.             #
  687.             exit 2
  688.             }
  689.        0    {
  690.             #
  691.             # Error in arguments
  692.             #
  693.             exit 1
  694.             }
  695.        default    {
  696.             #
  697.             # Desired information found
  698.             #
  699.             exit 0
  700.             }
  701.     }
  702.  
  703.    Thanks to Gerald W. Lester (gwlester@cpu.com). 
  704.  
  705. ------------------
  706.  
  707. From: Tcl Q&A
  708. Subject: Q21- How can I input and output binary data?
  709.  
  710.    With Extended Tcl you can safely do stuff like:
  711.  
  712.     set infp [open "|compress -dc $fileName"]
  713.     set outfp [open "|gzip -c $newFileName" w]
  714.  
  715.     copyfile $infp $outfp
  716.  
  717.    Thanks to Karl Lehenbauer (karl@NeoSoft.com) for the code example.
  718.  
  719.    A method of handling binary data one character at a time using
  720.    standard Tcl can be found in:
  721.    ftp.aud.alcatel.com:/tcl/code/binary-io-hack.shar.gz
  722.  
  723.    There are also two different extensions available that enable the
  724.    handling of binary data: tclbin and BinarIO. The former is better for
  725.    handling structured data, while the latter works better for binary
  726.    data streams. 
  727.  
  728. ------------------
  729.  
  730. From: Tcl Q&A
  731. Subject: Q22- How can I trap signals, and perform other more Unix specific
  732.     functions?
  733.  
  734.    Extended Tcl offers many of these types of functions. For instance,
  735.    extended Tcl has the signal command:
  736.  
  737.      signal action siglist [command]
  738.  
  739.      where action is one of "default", "ignore", "error", "trap", "get",
  740.      plus the POSIX "block" and "unblock" actions (available only on
  741.      POSIX systems, of course). Siglist is a list of either the symbolic
  742.      or numeric Unix signal (the SIG prefix is optional). Command is your
  743.      error handler (or a simple {puts stdout "Don't press *that* key!"}
  744.      :-)
  745.  
  746.    trap does what you expect, and I find error and get to be extremely
  747.    useful in interactive programs which demand keyboard traversal.
  748.  
  749.    Extended Tcl also has things like fork, etc.
  750.  
  751.    Answer by Brad Morrison (brad@NeoSoft.com). 
  752.  
  753. ------------------
  754.  
  755. From: Tcl Q&A
  756. Subject: Q23- How can I do a double indirect? - Why doesn't $$var work?
  757.  
  758.    There is one and only one level of substitution possible with every
  759.    pass through the interpreter. Also, when doing variable substitution,
  760.    the interpreter finds the dollar sign and then takes everything
  761.    following it up until the next invalid character (where invalid is
  762.    defined as anything other than a letter, digit, or underscore) as the
  763.    name of the variable - well, that is, unless it finds array notation
  764.    or the ${varname} form.
  765.  
  766.    In the case of $$var, the character after the first dollar sign is an
  767.    invalid character (another dollar sign), so there is no variable name
  768.    and variable substitution is not performed (the dollar sign is left as
  769.    is) and scanning starts again for any dollar signs and a following
  770.    variable name. It is immediately found at that second dollar sign, the
  771.    substitution is performed, and scanning for dollar signs resumes with
  772.    whatever was after the variable name. Since there isn't anything else,
  773.    substition is done for this pass through the interpreter (remember
  774.    it's only done once).
  775.  
  776.    The eval command runs it's arguments through the interpreter, so you
  777.    could use eval to cause a second pass through the interpreter, and
  778.    thus, have $$var work:
  779.  
  780.     % set a 5
  781.     5
  782.     % set var a
  783.     a
  784.     % puts $$var              # This doesn't work
  785.     $a
  786.     % eval puts $$var         # This does  - but it's dangerous
  787.     5
  788.  
  789.    However, if the contents of var contain any special characters (e.g.
  790.    whitespace, semicolon) you'll run into problems.
  791.  
  792.    A better method is to take advantage of the behaviour of the set
  793.    command when given only one argument, and combine command substitution
  794.    with variable substitution:
  795.  
  796.     % puts [set $var]         # This works safely
  797.     5
  798.  
  799.    or, in fact, you could use just command substitution (which is
  800.    performed once for each [ ] pair):
  801.  
  802.     % puts [set [set var]]    # as does this
  803.     5
  804.  
  805. ------------------
  806.  
  807. From: Tcl Q&A
  808. Subject: Q24- How can I get quoted strings to work the way I want?
  809.  
  810.    A long article dealing with the issues can be found at
  811.    ftp://ftp.aud.alcatel.com/tcl/docs/README.programmer.gz
  812.  
  813.    Here are some short answers:
  814.  
  815.    Q. I'm trying to build up a command for later execution but am having
  816.    trouble with variable values that include whitespace or special
  817.    characters.
  818.  
  819.    A. The safest way to build up commands is to use the list command so
  820.    that you can keep track of the list structure. Avoid using double
  821.    quotes because you can end up with an extra trip through the
  822.    evaluator. We'll illustrate this with a command to create a button
  823.    that prints out the label on the button when you click it.
  824.  
  825.      Wrong answer #1:
  826.  
  827.     button $myname -text $label -command "puts stdout $label"
  828.  
  829.      Why? because if $label has whitespace then the puts command will be
  830.      passed the wrong number of arguments. If $label has $ or [ ]
  831.      characters, they will be interpreted instead of printed.
  832.      Good answer #2:
  833.  
  834.     button $myname -text $label -command [list puts stdout $label]
  835.  
  836.      Why? because list will properly quote the value of $label
  837.  
  838.    Q. I'm trying to build up a command for later execution but am having
  839.    trouble getting some variables to evaluate now, and some to evaluate
  840.    later when the command is run.
  841.  
  842.    A. The cleanest way to do this is to define a procedure that hides the
  843.    use of the variables at run time, and then build up a call to that
  844.    procedure using the list command as described previously. (You can
  845.    even define the procedure on the fly. It will have global scope even
  846.    it if is created within another procedure.)
  847.  
  848.      Wrong answer #1:
  849.  
  850.     button $myname -text $label -command \
  851.         [list puts stdout $ArrayOfDynamicStuff($label)]
  852.  
  853.      Why? The array value will be substituted when the button is created,
  854.      not later on when the button is clicked. Also, note that the command
  855.      is executed at the global scope, so it is not necessary to include a
  856.      "global ArrayOfDynamicStuff" in the command.
  857.      Wrong answer #2 (backquotes and list):
  858.  
  859.     button $myname -text $label -command \
  860.         [list puts stdout \$ArrayOfDynamicStuff($label)]
  861.  
  862.      Why? Here the list command and the backquote of $ are fighting with
  863.      each other. The command ends up being something like:
  864.  
  865.     puts stdout {$ArrayOfDynamicStuff(foo)}
  866.  
  867.      which prevents the substitution of the value of the array element.
  868.      Dubious answer #3 (backquotes and double-quotes):
  869.  
  870.     button $myname -text $label -command \
  871.         "puts stdout \$ArrayOfDynamicStuff($label)"
  872.  
  873.      Why? This only works if the value of $label has no special
  874.      characters or whitespace.
  875.      Clean answer #4 (proc):
  876.  
  877.     proc doit { i } {
  878.         global ArrayOfDynamicStuff
  879.         puts stdout $ArrayOfDynamicStuff($i)
  880.     }
  881.     button $myname -text $label -command [list doit $label]
  882.  
  883.      Why? Using little TCL procs for your button commands is a good habit
  884.      because it eliminates most needs for fancy quoting, and it makes it
  885.      easier to tweak the button command later on.
  886.  
  887.    Q. I'm trying to pass along a variable number of args to another
  888.    procedure but I'm having trouble getting the $args to expand right.
  889.  
  890.    A. Avoid using eval and double quotes because that results in an extra
  891.    trip through the interpreter. The eval command will do a concat of its
  892.    arguments if there are more than one, so that pretty much eliminates
  893.    the need to group things with double quotes. Let's extend the button
  894.    example:
  895.  
  896.      Wrong answer #1:
  897.  
  898.     proc mybutton { myname label args } {
  899.         button $myname -text $label -command [list puts stdout $label] $args
  900.     }
  901.  
  902.      Why? All the extra arguments to mybutton are grouped into one list
  903.      element that is but into the value of $args. However, the button
  904.      command expects to see individual arguments, not a sub-list.
  905.      Wrong answer #2:
  906.  
  907.     proc mybutton { myname label args } {
  908.         eval "button $myname -text $label -command [list puts stdout $label] $a
  909. rgs"
  910.     }
  911.  
  912.      Why? The double quotes allow expansion of $label as well as $args,
  913.      so if $label has any whitespace, the button command will be
  914.      malformed
  915.      Good answer #3:
  916.  
  917.     proc mybutton { myname label args } {
  918.         set cmd {button $myname -text $label -command [list puts stdout $label]
  919. }
  920.         eval $cmd $args
  921.     }
  922.  
  923.      Why? Eval will first concatenate its two arguments and then run the
  924.      result through the interpreter. Think of this as stripping off the
  925.      outer curly braces from $cmd and $arg and making a single list with
  926.      all the elements of both. $label will be evaluated exactly once, so
  927.      the puts command will remain good, and whatever went into args will
  928.      also be processed exactly one time.
  929.  
  930.    Q. Why do I get a syntax error in an if/while/for statement?
  931.  
  932.    A. You may have written something like
  933.  
  934.     wish: set foo bar
  935.     wish: if {$foo == bar} {puts stdout bar}
  936.     syntax error in expression "$foo == bar"
  937.  
  938.    in which bar is interpreted as neither a string nor a variable, since
  939.    strings as operands in expressions MUST be surrounded by double quotes
  940.    or braces.
  941.  
  942.    Change to
  943.  
  944.     wish: if {$foo == "bar"} {puts stdout bar}
  945.  
  946.    or
  947.  
  948.     wish: if {$foo == {bar}} {puts stdout bar}
  949.  
  950.    always in expressions, depending on if you want expansion performed or
  951.    not.
  952.  
  953.    Contributed by Jesper Blommaskog (d9jesper@dtek.chalmers.se). 
  954.  
  955. ------------------
  956.  
  957. From: Tcl Q&A
  958. Subject: Q25- How can I share procedures between multiple tcl
  959.     applications?
  960.  
  961.    Rather than sourcing the files explicitly, build a tcl library:
  962.  
  963.    Step 1. Put the files in a common directory
  964.  
  965.    Step 2. Build the tclIndex for the "library". I use a Makefile with a
  966.    convention like:
  967.  
  968.     install.index:
  969.         (cd ${DESTDIR}/tclscripts/lib; \
  970.         echo 'source /usr/local/lib/tcl/init.tcl;\
  971.         auto_mkindex . *.tk' | tcl ; exit 0)
  972.  
  973.    Step 3. Modify your tcl scripts to reference the library:
  974.  
  975.    e.g.:
  976.  
  977.     # local additions
  978.     lappend auto_path /usr/local/lib/tcl_local $env(RDS_TCL_SCRIPTS)/lib
  979.  
  980.    Now, as soon as your script tried to reference a procedure in the
  981.    library, the "unknown" command autoloads the procedure for you.
  982.  
  983.    Contributed by Joe VanAndel (vanandel@ncar.ucar.edu). 
  984.  
  985. ------------------
  986.  
  987. From: Tcl Q&A
  988. Subject: Q26- How can I get items inserted into a list?
  989.  
  990.    A user asked why
  991.  
  992.     linsert $list 0 ..
  993.  
  994.    did not result in .. being inserted into list.
  995.  
  996.    Jesper Blommaskog (d9jesper@dtek.chalmers.se) replied:
  997.  
  998.    When doing list operations other than lappend, you must save the
  999.    returned value. This applies to list, lindex, lrange, and lreplace at
  1000.    least.
  1001.  
  1002.    In this example, you would perhaps want to do something like:
  1003.  
  1004.     set list [ linsert $list 0 .. ]
  1005.  
  1006. ------------------
  1007.  
  1008. From: Tcl Q&A
  1009. Subject: Q27- How can I perform a non-blocking read on a file identifier?
  1010.  
  1011.    From Frank Smith (frank@arraysystems.nstn.ns.ca) we are told that if
  1012.    you have Extended Tcl, you can
  1013.  
  1014.     read $fileId [fstat $fileId size]
  1015.  
  1016.    This will read only the number of bytes currently available on fileId
  1017.    and consequently will not block. 
  1018.  
  1019. ------------------
  1020.  
  1021. From: Tcl Q&A
  1022. Subject: Q28- How can I read and write from a pipe without locking up?
  1023.  
  1024.    The stdio package has an optimization for speed that buffers
  1025.    characters so that you can avoid un-necessary system calls. This isn't
  1026.    very good for interactive use so stdio changes it's behaviour if the
  1027.    file is a terminal. When you write to a pipe you are not writing to a
  1028.    terminal and so your output is buffered, similarly when the program at
  1029.    the other end of the pipe writes its response it is also buffered. The
  1030.    end result is the programs at both end of the pipe stall waiting for
  1031.    input. It is possible to force the buffers to be written using flush
  1032.    in Tcl and fflush() in C, often though, you don't have control over
  1033.    the program at the other end of the pipeline and in that case your
  1034.    only solution is to use a pseudo-teletype (pty). Unfortunately this
  1035.    isn't all that easy.
  1036.  
  1037.    While this isn't directly supported in Tcl, the spawn command in
  1038.    expect opens a pty and starts a command. 
  1039.  
  1040. ------------------
  1041.  
  1042. From: Tcl Q&A
  1043. Subject: Q29- How can I find what version I am running?
  1044.  
  1045.    Well, there is no one answer to this. Tcl itself will tell you it's
  1046.    version if you type:
  1047.  
  1048.     info tclversion
  1049.  
  1050.    On the other hand, to get the Tk version, you must use:
  1051.  
  1052.     puts $tk_version
  1053.  
  1054.    Other extensions use other means (for example, Extended Tcl uses
  1055.    "infox version" to return it's version number). 
  1056.  
  1057. ------------------
  1058.  
  1059. From: Tcl Q&A
  1060. Subject: Q30- How can I use variables to hold array names?
  1061.  
  1062.    Eric Bleeker (ericbl@paramount.nikhefk.nikhef.nl) has written:
  1063.  
  1064.      You may have written something like:
  1065.  
  1066.     % set foo "bar baz"
  1067.     bar baz
  1068.     % foreach aap $foo {
  1069.         set $aap(1) "something"
  1070.     }
  1071.     can't read "aap(1)": variable isn't array
  1072.  
  1073.      This means Tcl tries to substitute the array element aap(1) which
  1074.      doesn't exist. To fix this use:
  1075.  
  1076.     % foreach aap $foo {
  1077.         set [set aap](1) "something"
  1078.     }
  1079.  
  1080.      In this case two arrays bar and baz are created.
  1081.  
  1082.    An alternative format is:
  1083.  
  1084.     % foreach aap $foo {
  1085.         set ${aap}(1) "something"
  1086.     }
  1087.  
  1088.      _________________________________________________________________
  1089.  
  1090.   PLATFORM SPECIFIC AND PORTABILITY RELATED QUESTIONS:
  1091.  
  1092. ------------------
  1093.  
  1094. From: Tcl Q&A
  1095. Subject: Q31- How can I create shared Tcl/Tk libraries on AIX
  1096.  
  1097.    Dov Grobgeld (dov@menora.weizmann.ac.il) provided info on creating Tcl
  1098.    and Tk shared libraries under AIX 3.1.5:
  1099.  
  1100.      For Tcl:
  1101.  
  1102.     cc -o tkshar.o *.o -bE:tclshar.exp -bM:SRE -berok -lX11 -lm
  1103.     ar r libtclshr tclshar.o
  1104.  
  1105.      For Tk:
  1106.  
  1107.     cc -o tkshar.o *.o -bE:tkshar.exp -bM:SRE -berok -Ltcl -lX11 -lm -ltclshr
  1108.     ar r libtkshr tkshar.o
  1109.  
  1110.      where tckshar.exp and tkshar.exp had lists of the external
  1111.      functions.
  1112.  
  1113.      There are also problems with fonts on AIX and the IBM. A patch is
  1114.      needed from IBM to fix the X server so that fonts are working
  1115.  
  1116. ------------------
  1117.  
  1118. From: Tcl Q&A
  1119. Subject: Q32- Has anyone gotten Tcl to compile under HP-UX?
  1120.  
  1121.    See the porting notes. Also, be aware that there have been some
  1122.    reports of Configure assuming that you should use the compatibility
  1123.    version of opendir() and that you have no dirent.h . This causes
  1124.    glob-ing to fail, as well as TclX's readdir, etc.
  1125.  
  1126.    Changing tcl7.3 to remove the opendir compatibility file and removing
  1127.    the -DNO_DIRENT, -DUSE_DIRENT2 fixed it all up. 
  1128.  
  1129. ------------------
  1130.  
  1131. From: Tcl Q&A
  1132. Subject: Q33- Has anyone gotten Tcl to compile under VMS?
  1133.  
  1134.    Information from John Kimball (jkimball@src.honeywell.com) on May 4,
  1135.    1993 was that he had gotten Tcl 6.7 and Tk 3.2 ported to VMS 5.5. See
  1136.    the catalog for the file information. 
  1137.  
  1138. ------------------
  1139.  
  1140. From: Tcl Q&A
  1141. Subject: Q34- What does it take to get Tcl to compile under SCO Unix?
  1142.  
  1143.    Add a "#undef select" to tkEvent.c, and remove the reference to
  1144.    TK_EXCEPTION around line 460 of main.c.
  1145.  
  1146.    Tk uses its own scheme for allocating the border colors for its 3D
  1147.    widgets, which causes problems when running TK on a system with
  1148.    "PseudoColor" display class, and a 16-cell colormap.
  1149.  
  1150.    If you can't go to eight bitplanes, you can instead start the server
  1151.    with a "-static" (Xsco) or "-analog" (Xsight) option, making the
  1152.    display class become "StaticColor". This makes the entire colormap
  1153.    read-only, and it will return the color that most closely maps to the
  1154.    desired color as possible.
  1155.  
  1156.    This information is from Keith Amann (Keith_Amann@stortek.com). 
  1157.  
  1158. ------------------
  1159.  
  1160. From: Tcl Q&A
  1161. Subject: Q35- Why do I get format and scan errors when I run tclTest?
  1162.  
  1163.    That's a problem (scanf/printf) many systems seem to have. Don't worry
  1164.    too much about it - just don't use these 'advanced' features. If
  1165.    you're hacking C, you'll have the same problems.
  1166.  
  1167.    For instance, printf("%Ng", double_value) and strtod("+",&terminal)
  1168.    produce incorrect results. 
  1169.  
  1170. ------------------
  1171.  
  1172. From: Tcl Q&A
  1173. Subject: Q36- Why do I get lots of errors under Irix 4.0.1 when I run
  1174.     tclTest?
  1175.  
  1176.    There's a bug in the 4.0.1 optimizer that's fixed in 4.0.2. Compile
  1177.    tclVar.c using -O0 (no optimization). 
  1178.  
  1179. ------------------
  1180.  
  1181. From: Tcl Q&A
  1182. Subject: Q37- Does anyone else have problems with Tcl on a Cray?
  1183.  
  1184.    See the porting notes for a set of changes mentioned. Also, Booker C.
  1185.    Bense (benseb@grumpy.sdsc.edu) reports that version 3.0.1.6 has some
  1186.    real problems with char pointers, causing Tcl to crash. Using version
  1187.    3.0.2.1, things are much better, except for a minor formatting problem
  1188.    and serious problems with scan. 
  1189.  
  1190. ------------------
  1191.  
  1192. From: Tcl Q&A
  1193. Subject: Q38- How do I install Tcl 7.1/Tk 3.4 on NeXTSTEP 3.1?
  1194.  
  1195.    I have indicated in the past that this particular question seems to
  1196.    generate controversy - I have replaced previous explanations with the
  1197.    latest msg from someone who sounds authoritative...
  1198.  
  1199.    From: Robert Nicholson (robert@steffi.demon.co.uk)
  1200.  
  1201.      This is for TCL7.1 and TK3.4
  1202.  
  1203.      This is a variation on Thomas Funke's entry. 
  1204.  
  1205. ------------------
  1206.  
  1207. From: Tcl Q&A
  1208. Subject: Q39- Installing TCL7.1 on NeXT
  1209.  
  1210.      To install tcl7.1 on NeXTSTEP 3.1 you must:
  1211.      * run configure with predefined CPP:
  1212.        type "sh" to run a Bourne shell. then type
  1213.  
  1214.     CPP='cc -E' ./configure
  1215.      * edit Makefile:
  1216.        add tmpnam.o to COMPAT_OBJS:
  1217.  
  1218.   COMPAT_OBJS =      getcwd.o waitpid.o strtod.o tmpnam.o
  1219.  
  1220.      At this point you probably want to rename the all calls to strtod
  1221.      and tmpnam to something else in order to distinguish them from those
  1222.      that are supplied in the NeXT libraries libsys_a.a. You can do this
  1223.      by adding the following line to AC_FLAGS
  1224.  
  1225.     -Dstrtod=newstrtod -Dtmpnam=newtmpnam
  1226.  
  1227.      and renaming the names of the definitions in the appropriate
  1228.      compat/*.c files.
  1229.  
  1230.      To check everything is working correctly open a tclsh
  1231.  
  1232.     % expr {"0" == "+"}
  1233.     0
  1234.  
  1235.      Using the wrong strtod function will cause this test to return 1
  1236.      which is a serious error. Ignore the precision errors. 
  1237.  
  1238. ------------------
  1239.  
  1240. From: Tcl Q&A
  1241. Subject: Q40- Installing TK3.4 on NEXTSTEP 3.1
  1242.  
  1243.      There is a call to strtod in TK3.4 so you should link against
  1244.      ../tcl-7.1/compat/strtod.o and apply the -Dstrtod=newstrtod to
  1245.      AC_FLAGS in Tk also.
  1246.  
  1247.      Note:Tk's raise test will fail when running the tvtwm window
  1248.      manager. Changing to either twm or even better fvwm ensures that
  1249.      this test will succeed.
  1250.  
  1251. ------------------
  1252.  
  1253. From: Tcl Q&A
  1254. Subject: Q41- Why can't I print the draft of the Tcl/Tk book?
  1255.  
  1256.    From John Ousterhout (John.Ousterhout@Eng.Sun.COM):
  1257.  
  1258.    Here's my form letter that seems to explain most of the problems
  1259.    people have had printing parts of the book:
  1260.  
  1261.    Some old versions of the Transcript spooler software cannot properly
  1262.    handle encapsulated Postscript files within another Postscript file
  1263.    when they do page reversal. They tend to garble the page structure of
  1264.    the file, causing an error at the point of the first EPS file. Part II
  1265.    of the Tcl book has lots of EPS files embedded in it, one for each
  1266.    screen dump. If your printer cannot print this file I suggest checking
  1267.    to see if page reversal is enabled for your printer. If so, try asking
  1268.    your local system wizard to disable it for you; this should allow the
  1269.    file to print. Or, find some other way to dump the Postscript file
  1270.    directly to the printer without going through the spooling software
  1271.    (e.g. perhaps you can simply cat it to the printer's serial port).
  1272.  
  1273.    Others have suggested:
  1274.  
  1275.    The embedded pictures have CR as the line separator instead of LF and
  1276.    this may be causing the problem. Try translating them to LFs ...
  1277.  
  1278.     tr '\015' '\012' <book.p2.ps >fixedbook.p2.ps
  1279.  
  1280.    and:
  1281.  
  1282.    This is not the original poster's problem but in countries using A4
  1283.    paper and on a particular printer, the Dataproducts LZR1260E, the
  1284.    frame size causes the printing to be stretched vertically. This
  1285.    happens with other Framemaker generated documents by the way. A PS
  1286.    interpreter bug no doubt. The fix is to edit the dimensions for A4
  1287.    paper. This shell script does both fixes.
  1288.  
  1289.     #!/bin/sh
  1290.     cat $1 | tr '\015' '\012' | sed '/FMDOCUMENT$/s/612 792/595 842/'
  1291.  
  1292. ------------------
  1293.  
  1294. From: Tcl Q&A
  1295. Subject: Q42- Why am I getting errors on my SGI Indigo workstation?
  1296.  
  1297.    From Gordon Lack (gml4410@ggr.co.uk) we are told that the SGI c
  1298.    compiler has some bugs with variable arguments.
  1299.  
  1300.    tclVar.c must be compiled with -O0 at IRIX C 4.0.1 because of a
  1301.    compiler bug with varargs.
  1302.  
  1303.    Done by placing specific rule into Makefile.
  1304.  
  1305.     # GGR SG needs -O0 for varargs at 4.0.1
  1306.  
  1307.     CC_SWITCHES0 =  -O0 -I. -I${SRC_DIR} ${AC_FLAGS} ${MATH_FLAGS} \
  1308.           ${GENERIC_FLAGS} ${PROTO_FLAGS} ${MEM_DEBUG_FLAGS} \
  1309.           -DTCL_LIBRARY=\"${TCL_LIBRARY}\"
  1310.  
  1311.     tclVar.o: tclVar.c
  1312.           $(CC) -c $(CC_SWITCHES0) $<
  1313.  
  1314.    Peter Neelin (neelin@pet.mni.mcgill.ca) also noted that:
  1315.  
  1316.    I get tclX 7.3a to compile on an SGI (irix 4.0.5) with the following
  1317.    changes to the Config.mk file:
  1318.  
  1319.     71c71
  1320.     < CFLAGS=-cckr -D__GNU_LIBRARY__
  1321.     ---
  1322.     > #CFLAGS=
  1323.     106,107c106,107
  1324.     < TCL_PLUS_BUILD=TCL_PLUS
  1325.     < CCPLUS=g++
  1326.     ---
  1327.     > #TCL_PLUS_BUILD=TCL_PLUS
  1328.     > CCPLUS=CC
  1329.     191,193c191
  1330.     < MAN_DIR_SEPARATOR=
  1331.     <
  1332.     < LIBOBJS=strftime.o
  1333.     ---
  1334.     > #MAN_DIR_SEPARATOR=.
  1335.  
  1336.    The -D__GNU_LIBRARY solves the srandom problem and I think that the
  1337.    -cckr gets around the prototype error with waitpid (it's crude, but it
  1338.    works). I've forgotten why I needed the strftime.
  1339.  
  1340.    If you want the version of Config.mk that worked for me, send me mail.
  1341.  
  1342. ------------------
  1343.  
  1344. From: Tcl Q&A
  1345. Subject: Q43- How do I build expect on Solaris 2.3?
  1346.  
  1347.    From Jeff Abramson (jra@hrcms.jazz.att.com) we are told that,
  1348.  
  1349.      using either SunPro cc 2.0.1 or gcc 2.5.8 with no problems. For
  1350.      SunPro I do:
  1351.  
  1352.     CC=cc ./configure --prefix=directory_of_your_choice
  1353.     make CC=cc
  1354.  
  1355.      For gcc I do:
  1356.  
  1357.     CC="gcc -fwritable-strings" ./configure \
  1358.         --prefix=directory_of_your_choice
  1359.     make CC="gcc -fwritable-strings"
  1360.  
  1361. ------------------
  1362.  
  1363. From: Tcl Q&A
  1364. Subject: Q44- How do I port Tcl and Tk to a Sequent?
  1365.  
  1366.    From Andrew Swan (aswan@soda.berkeley.edu) we find:
  1367.  
  1368.      For both Tcl and Tk, I used gcc rather than the Sequent cc which is
  1369.      not ansi.
  1370.  
  1371.      For Tcl, there were a couple of problems with the math library.
  1372.      First, the Sequent math library doesn't include the 'fmod' function.
  1373.      I got the source for fmod from ftp.uu.net, put it in the compat
  1374.      subdirectory, and added it to the Makefile. fmod also wanted
  1375.      functions 'isnan' and 'finite' but I just commented those out since
  1376.      I don't believe tcl supports infinity and nan.
  1377.  
  1378.      The other problem with the math library was that it has two copies
  1379.      of the 'tanh' function in it. This is easy to fix by using "ar" to
  1380.      separate the library in to object files and then reconstruct it,
  1381.      leaving one of the copies of tanh out.
  1382.  
  1383.      With those changes, Tcl compiled cleanly and passed all the tests
  1384.      except the scanning tests. Apparently, the *scanf functions are
  1385.      broken in Dynix. The problem is with recognizing the end of octal
  1386.      numbers, and I just let this problem go. Fixing it would probably
  1387.      involve finding source to the *scanf functions and including it.
  1388.  
  1389.      To compile Tk, I had to make a new version of stddef.h including
  1390.      things like wchar_t. I just copied it in to another include
  1391.      directory and put that directory first and then tweaked the copy. Tk
  1392.      also had the math library problem (tanh). Other than those, however,
  1393.      everything compiled cleanly and passed all the tests.
  1394.  
  1395. ------------------
  1396.  
  1397. From: Tcl Q&A
  1398. Subject: Q45- How do I get around the symbol table full msg in AU/X 3.0?
  1399.  
  1400.    After getting things compiled on AU/X, you have to be sure to do the
  1401.    links with the -A {factor} arguments which expand the default table
  1402.    allocations. {factor} is the amount by which the compiler multiplies
  1403.    the default allocation. Try -A 2. Contact Walter B. Kulecz, PhD.
  1404.    (wkulecz@medics.jsc.nasa.gov) for more details of his port. 
  1405.  
  1406. ------------------
  1407.  
  1408. From: Tcl Q&A
  1409. Subject: Q46- How do I compile Tcl on MS-DOS, MacOS, or other non-UNIX
  1410.     system?
  1411.  
  1412.    Refer to Larry Virden's FAQ (see tcl-faq/part1) or (see tcl-faq/part4)
  1413.    for details concerning tools, finished ports, or mailing lists
  1414.    relating to this topic. 
  1415.  
  1416. ------------------
  1417.  
  1418. From: Tcl Q&A
  1419. Subject: Q47- How do I get Tcl to compile on my QNX system?
  1420.  
  1421.    Steve Furr (furr@qnx.com) indicates:
  1422.  
  1423.    For the record, to get TCL to work under QNX, I had to:
  1424.      * Make the _POSIX_SOURCE change indicated for pathname lengths
  1425.      * Change a definition of VARARGS, so the Watcom ANSI C compiler
  1426.        would accept varargs functions used.
  1427.      * Resolve a conflict with error codes defined by QNX.
  1428.  
  1429. ------------------
  1430.  
  1431. From: Tcl Q&A
  1432. Subject: Q48- Why do I get the error message "Command not found" when I
  1433.     try to run a Tcl script?
  1434.  
  1435.    The script probably starts with a #! that is followed by a path to the
  1436.    Tcl interpreter that is too long for your system. Many Unix systems
  1437.    are limited 32 characters in this regard. So, something like this will
  1438.    fail:
  1439.  
  1440.         #! /usr/home/homedir/very/long/path/tclsh
  1441.  
  1442.         # rest of script
  1443.  
  1444.    You can either shorten the path by moving the tclsh executable to a
  1445.    different directory or by using symbolic links. Another option is to
  1446.    not specify the path at all. See the question "How do I make my script
  1447.    executable regardless of the location of tclsh?" for an example of
  1448.    how to do this.
  1449.      _________________________________________________________________
  1450.  
  1451. End of FAQ
  1452.